home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / UTIL.C < prev    next >
C/C++ Source or Header  |  1995-01-30  |  8KB  |  265 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81. #include <windows.h>
  82. #include <stdio.h>
  83. #include <stdlib.h>
  84. #include <string.h>
  85.  
  86. #undef MIN
  87. #define MIN(x,y)    (((x) < (y) ) ? (x) : (y))
  88. static char *memmsg = "Can't allocate memory";
  89.  
  90. void
  91. upperCase(string)
  92. char *string;
  93. {
  94.     int i, l;
  95.     l = strlen(string);
  96.     for (i = 0; i < l; i++) {
  97.         if (string[i] >= 'a' && string[i] <= 'z')
  98.             string[i] -= 'a' - 'A';
  99.     }
  100. }
  101.  
  102.  
  103. void
  104. lowerCase(cp)
  105. register char *cp;
  106. {
  107.     char *lastp;
  108.     
  109.     for (lastp = cp + strlen(cp); cp < lastp; cp++)
  110.         if (*cp >= 'A' && *cp <= 'Z')
  111.             *cp -= 'A' - 'a';
  112. }
  113.  
  114.  
  115. char *
  116. stripLeadingSpace(cp)
  117. register char *cp;
  118. {
  119.     while (cp && *cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
  120.         cp++;
  121.     return cp;
  122. }
  123.  
  124. void
  125. stripTrailingSpace(s)
  126. register char *s;
  127. {
  128.     register char *t;
  129.  
  130.     if (!s)
  131.         return;
  132.     t = s + strlen(s) - 1;
  133.     while ((t >= s) && ((*t == ' ') || (*t == '\t') || (*t == '\n')))
  134.         t--;
  135.     *(++t)= 0;
  136. }
  137.  
  138. /*
  139.  * Save a string in alloc'd memmory.
  140.  */
  141. char *
  142. saveString(s)
  143. char *s;
  144. {   
  145.     char *t;
  146.     extern void fatal(char *);
  147.  
  148.     if ((t = (char *) (LPVOID) LocalAlloc(LMEM_FIXED, strlen(s)+1)) == NULL)
  149.         fatal(memmsg);
  150.     strcpy(t, s);
  151.     return t;
  152. }
  153.  
  154.  
  155. /*
  156.  * Allocate memory with error checking.
  157.  */
  158.  
  159. void *
  160. safeAlloc(size)
  161. int size;
  162. {
  163.     char *p;
  164.     extern void fatal(char *);
  165.  
  166.     if ((p = GlobalAlloc(GPTR, size)) == NULL)
  167.         fatal(memmsg);
  168.     return p;
  169. }
  170.  
  171. void
  172. safeFree(bufp)
  173. void *bufp;
  174. {
  175.     if (bufp)
  176.         LocalFree(bufp);
  177. }
  178.  
  179. char *
  180. ErrorString(int errcode)
  181. {
  182.     extern char *StrError(int);
  183.     return StrError(errcode);
  184. }
  185.  
  186.  
  187. char *
  188. getline(buf, size, fp)
  189. char *buf;
  190. int size;
  191. FILE *fp;
  192. {
  193.     char *cp;
  194.  
  195.     if (!fp)
  196.         return NULL;
  197.  
  198.     if (fgets(buf, size, fp) == NULL)
  199.         return NULL;
  200.  
  201.     cp = stripLeadingSpace(buf);
  202.     stripTrailingSpace(buf);
  203.     return cp;
  204. }
  205.  
  206.  
  207. int
  208. cistrcmp(src,dst)
  209. char *src,*dst;
  210. {
  211.     char d[64],s[64];
  212.     register char *dp, *sp;
  213.  
  214.     for (sp=s; sp<(s+63) && *src; src++) {
  215.         if (*src == ' ' || *src == '\t')
  216.             continue;
  217.         if (isupper(*sp = *src))
  218.             *sp = tolower(*sp);
  219.         sp++;
  220.     }
  221.     *sp = 0;
  222.     for (dp=d; dp<(d+63) && *dst; dst++) {
  223.         if (*dst == ' ' || *dst == '\t')
  224.             continue;
  225.         if (isupper(*dp = *dst))
  226.             *dp = tolower(*dp);
  227.         dp++;
  228.     }
  229.     *dp = 0;
  230.     return strcmp(s, d);
  231. }
  232.  
  233. static HANDLE hlib;
  234.  
  235. void *
  236. LibFunc(const char *fname)      /* DANGER: NOT re-entrant!!! */
  237. {
  238.     void *fp;
  239.     extern void usermsg(const char *);
  240.     extern char *dllloadmsg;
  241.     extern char tmpbuf[], dllname[];
  242.  
  243.     if (!hlib) {
  244.         hlib = LoadLibrary(dllname);
  245.         if (!hlib) {
  246.             sprintf(tmpbuf, "%s: error code %d", dllloadmsg,
  247.                 ErrorString(GetLastError()));
  248.             usermsg(tmpbuf);
  249.             return NULL;
  250.         }
  251.     }
  252.     fp = GetProcAddress(hlib, fname);
  253.     return fp;
  254. }
  255.  
  256. void
  257. LibClose()                      /* DANGER: NOT re-entrant!!! */
  258. {
  259.     if (!hlib) {
  260.         FreeLibrary(hlib);
  261.         hlib = NULL;
  262.     }
  263. }
  264.  
  265.